<?php
namespace app\user\controller;
use app\common\controller\Common;
use think\Request;
class Consult extends Common
{
	protected $model = null;
	protected $keyword_search = ['oc.user_sn','oc.username','oc.phone','cg.goods_name'];

	public function _initialize()
	{
		parent::_initialize();
        $this->model = model('Consult');
	}
	/**
	 * 客户咨询列表
	 */
	public function index()
	{
		if(Request()->isGet()){
			$data = input('get.');
			if(Request()->isAjax()){
				return $this->getList($data);
			}
			/*@产品分类*/
			$cate = model('Category')->where('fid',0)->select();
			$this->assign('cate',$cate);
			return $this->fetch('');
		}
	}
	/**
	 * 客户订单详情
	 */
	public function details($ids = null)
	{
		$row = $this->model->get($ids);
		$goods = $this->model->consultGoods($ids);
		$img = $this->model->consultImg($ids);
		if(Request()->isGet()){
			$this->assign('img',$img);
			$this->assign('goods',$goods);
			$this->assign('row',$row);
			return $this->fetch('');
		}
	}
	/**
	 * 列表查询条件处理
	 * @param array $data 查询参数
	 */
	protected function handleList($data)
	{
		$where = [];
		/*@用户编号*/
		if(isset($data['user_sn']) && $data['user_sn'] != ''){
			$where['oc.user_sn'] = $data['user_sn'];
		}
		/*@产品分类*/
		if(isset($data['category_id']) && $data['category_id'] != ''){
			$where['cg.category_id'] = $data['category_id'];
		}
		/*@产品子分类*/
		if(isset($data['cat_id']) && $data['cat_id'] != ''){
			$where['cg.cat_id'] = $data['cat_id'];
		}
		/*@产品品牌*/
		if(isset($data['brand_name']) && $data['brand_name'] != ''){
			$where['cg.brand_name'] = $data['brand_name'];
		}
		/*@产品内存*/
		if(isset($data['memory_name']) && $data['memory_name'] != ''){
			$where['cg.memory_name'] = $data['memory_name'];
		}
		/*@产品属性*/
		if(isset($data['attribute_name']) && $data['attribute_name'] != ''){
			$where['cg.attribute_name'] = $data['attribute_name'];
		}
		/*@产品颜色*/
		if(isset($data['colour_name']) && $data['colour_name'] != ''){
			$where['cg.colour_name'] = $data['colour_name'];
		}

		/*@时间区间*/
		if(isset($data['start']) && $data['start'] != '' && isset($data['end']) && $data['end'] != ''){
			if(strtotime($data['start']) > strtotime($data['end'])){
				return false;
			}
			$where['oc.addtime'] = [
				['egt', strtotime($data['start'])],
				['lt', strtotime($data['end'])]
			];
		}else if(isset($data['start']) && $data['start'] != ''){
			$where['oc.addtime'] = ['egt', strtotime($data['start'])];
		}else if(isset($data['end']) && $data['end'] != ''){
			$where['oc.addtime'] = ['lt', strtotime($data['end'])];
		}
		return $where;
	}
}